
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>物品信息表格</title>
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css">
    <link rel="stylesheet" href="__PUBLIC__/static/css/style.css">
    <link rel="icon" href="__PUBLIC__/static/image/code.png">
</head>
<body class="body">



<div class="tab-top">
{if ahuthbtn('add')}
  <a class="layui-btn site-demo-active layui-btn-sm" id="addview" data-href="{:url('admin/Welfare/add')}"><i class="layui-icon layui-icon-add-circle"></i>申请物品信息</a>
{/if}
<div class="search">
  <form class="layui-form" action="">
  <div class="layui-inline">
    <input class="layui-input layui-input-sm" name="search" placeholder="请输入角色昵称" id="search-elm" autocomplete="off" value="{$search}">
  </div>
  <button class="layui-btn site-demo-active layui-btn-sm search-btn" data-type="reload">搜索</button>
</form>
</div>

</div>


<div class="layui-form">
  <table class="layui-table" lay-filter="parse-table-demo" id="test33" style="display:none">
    <thead>
      <tr>
        <th lay-data="{type:'checkbox', fixed: 'left'}"></th>
        <th lay-data="{field:'id', width:50}">ID</th>
        <th lay-data="{field:'applicantid', width:100}">申请人</th>
        <th lay-data="{field:'create_time', width:180}">申请时间</th>
        <th lay-data="{field:'name', width:100}">角色</th>
        <th lay-data="{field:'type', minwidth:200}">物品内容</th>
		<th lay-data="{field:'partition', width:150}">分区</th>
        <th lay-data="{field:'remark', width:150,edit: 'text'}">备注</th>
        <th lay-data="{field:'update_time', width:180}">审核时间</th>
        <th lay-data="{field:'auditorid', width:100}">审核人</th>
        <th lay-data="{field:'sendstatus', width:100, align:'center'}">发送状态</th>
        <th lay-data="{field: 'sign', width:150, align:'center'}">操作</th>
      </tr> 
    </thead>
    <tbody>
{foreach $list as $key=>$vo } 
      <tr>
        <td></td>
        <td>{$vo.id}</td>
        <td>{$vo.applicantid}</td>
        <td>{$vo.create_time|date='Y-m-d H:i:s'}</td>
        <td>{$vo.name}</td>
        <td>{$vo.goods}</td>
		<td>{$vo.partition}</td>
        <td>{$vo.remark}</td>
        <td>{$vo.update_time ? date('Y-m-d H:i:s',$vo.update_time) : ""}</td>
        <td>{$vo.auditorid ? $vo.auditorid : ""}</td>
        <td data-id="{$vo.sendstatus}">
          {if $vo.status == 1}
          {if $vo.sendstatus == 1}
         <a class="layui-btn layui-btn-xs layui-audit layui-btn-primary layui-btn-disabled" data-href="" data-id="{$vo.id}"><i class="layui-icon"></i> 成功 </a> 
         {elseif $vo.sendstatus == 2/}
         {if ahuthbtn('audit')}
         <a class="layui-btn layui-btn-xs layui-audit" data-href="{:url('admin/Welfare/sendstatus')}" data-id="{$vo.id}" id="send-status"><i class="layui-icon"></i> 失败 </a> 
         {/if}
         {else /}
         {if ahuthbtn('audit')}
          <a class="layui-btn layui-btn-xs layui-audit" data-href="{:url('admin/Welfare/sendstatus')}" data-id="{$vo.id}"><i class="layui-icon" id="send-status"></i> 发送 </a> 
          {/if}
         {/if}
         {/if}

        </td>
        <td> 
          {if $vo.status != 1}
          {if ahuthbtn('audit')}
         <a class="layui-btn layui-btn-xs layui-audit" data-href="{:url('admin/Welfare/audit')}" data-id="{$vo.id}"><i class="layui-icon"></i> 审 核 </a> 
         {/if}
         {else /}
         <a class="layui-btn layui-btn-xs layui-audit layui-btn-primary layui-btn-disabled" data-href="" data-id="{$vo.id}"><i class="layui-icon"></i> 已 审 </a> 
          {/if}
          {if ahuthbtn('audit')}
         <a class="layui-btn layui-btn-danger layui-btn-xs article-del" data-href="{:url('admin/Welfare/delete',['id'=>$vo.id])}"><i class="layui-icon"></i> 删 去</a>
         {/if}
     </td>
      </tr>
{/foreach}
    </tbody>
  </table>

</div>

<div class="list-page layui-row">{$page|raw}</div>
<div class="list-all-btn layui-row">
{if ahuthbtn('delall')}
<a class="layui-btn layui-btn-danger layui-btn-sm" data-type="tabdel" id="alldel"><i class="layui-icon layui-icon-delete"></i>批量删去</a>
{/if}
{if ahuthbtn('auditall')}
<a class="layui-btn layui-btn-sm" data-type="tabdel" id="allaudit"><i class="layui-icon layui-icon-ok"></i>批量审核</a>
{/if}
{if ahuthbtn('sendall')}
<a class="layui-btn layui-btn-normal layui-btn-sm" data-type="tabdel" id="allsend"><i class="layui-icon layui-icon-release"></i>批量发送</a>
{/if}
</div>
<script type="text/javascript" src="__PUBLIC__/layui/layui.js"></script>
<script src="__ADMIN__/js/comm.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
layui.use(['form', 'table', 'admin'], function() {
    var $ = layui.jquery,
        form = layui.form,
        table = layui.table,
        admin = layui.admin;
    $('.search-btn').on('click', function() {
        //$('#search-elm').val();
        location.href = "{:url('admin/Welfare/index')}?search=" + $('#search-elm').val();
        //active[type] ? active[type].call(this) : '';
        return false;
    });
    table.init('parse-table-demo', { //转化静态表格
        //height: 'full-500'
        id: 'idTest',
    });
    //添加
    $('#addview').click(function() {
        layer.open({
            title: $(this).text(),
            type: 2,
            area: ['900px', '600px'],
            fixed: false, //不固定
            maxmin: true,
            content: $(this).attr('data-href')
        });
    });

    $('.layui-audit').click(function() {
        that = $(this);
        if (that.hasClass('layui-btn-disabled')) {
            return;
        }
        var url = that.attr('data-href');
        $.post(url, {
            id: that.attr('data-id'),
            status: 1
        }, function(data) {
            console.log(data);
            if (data.code == 1) {
                that.parents('tr').find('.laytable-cell-1-update_time').text(data.data.update_time); //审核时间
                that.parents('tr').find('.laytable-cell-1-auditorid').text(data.data.auditorid); //审核时间
                that.addClass('layui-btn-primary layui-btn-disabled');
                that.text('已 审');
                //that.parents('tr').find('.laytable-cell-1-sendstatus').html('<a class="layui-btn layui-btn-xs layui-audit" data-href=' + "{:url('admin/Welfare/sendstatus')}" + ' id="send-status"><i class="layui-icon"></i> 发送 </a>');
                if(data.data.cdata == 1){
                    that.parents('tr').find('.laytable-cell-1-sendstatus').html('<a class="layui-btn layui-btn-xs layui-audit layui-btn-primary layui-btn-disabled" data-href=""><i class="layui-icon"></i> 成功 </a>');

                }else{
                    that.parents('tr').find('.laytable-cell-1-sendstatus').html('<a class="layui-btn layui-btn-xs layui-btn-danger layui-audit send-status" data-href=' + "{:url('admin/Welfare/sendstatus')}" + '><i class="layui-icon"></i> 失败 </a>');
                }
                layer.msg(data.msg);
            } else {
                layer.msg(data.msg);
            }
        });
    });

    $('.send-status').unbind('click').click(function(event) {
        var that = $(this);
        //$(this).addClass('layui-btn-disabled');
        //console.log(that.attr('data-href'),that.attr('data-id'),'123');
        $.post(that.attr('data-href'), {
            id: that.attr('data-id')
        }, function(data) {
            console.log(data);
            if (data.code == 1) {
                if(data.data == 1){
                    that.attr('data-href','');
                    that.addClass('layui-btn-disabled');
                    that.text('成功');
                    layer.msg(data.msg);
                }else{
                    that.addClass('layui-btn-danger');
                    that.text('失败');                   
                    layer.msg(data.msg); //失败
                }
            } else {
                layer.msg(data.msg);
            }
        }); 
    });

    //监听单元格编辑
    table.on('edit(parse-table-demo)', function(obj) {
        //console.log('d','dss')
        var value = obj.value //得到修改后的值
            ,
            data = obj.data; //得到所在行所有键值
        $.post("{:url('admin/Welfare/quickedit')}", {
            id: data.id,
            remark: value
        }, function(data) {
            if (data.code == 1) {
                layer.msg(data.msg);
                //layer.tips(data.msg, obj.othis);
            } else {
                layer.msg(data.msg);
            }
        });
    });
    //监听工具条
    $('.article-del').click(function() {
        that = $(this);
        layer.confirm('真的删除行么', function(index) {
            url = that.attr('data-href');
            //admin.actAuth(url,function(){
            $.get(url, function(data) {
                if (data.code === 0) {
                    layer.msg(data.msg);
                } else {
                    that.parents('tr').remove();
                    layer.msg(data.msg);
                }
            });
        });
    });
    /**
     * 批量删去
     */
    $('#alldel').on('click', function() {
        var checkStatus = table.checkStatus('idTest'),
            checkStatusdata = checkStatus.data;
        var checkStatuslist = '';
        $.each(checkStatusdata, function(i, obj) {
            checkStatuslist += obj.id + ',';
        });
        checkStatuslist = checkStatuslist.substr(0, (checkStatuslist.length - 1));
        var ids = checkStatuslist; //得到 1，2，4
        var url = "{:url('admin/Welfare/delall')}";
        var sUrl = "{:url('admin/Welfare/index')}";
        var eUrl = "{:url('admin/Welfare/index')}";
        //deleteAll(ids,请求的url,操作成功跳转url,操作失败跳转url)
        admin.deleteAll(ids, url, sUrl, eUrl);
    });
    /**
     * 批量审核
     */
    $('#allaudit').on('click', function() {
        var checkStatus = table.checkStatus('idTest'),
            checkStatusdata = checkStatus.data;
        var checkStatuslist = '';
        $.each(checkStatusdata, function(i, obj) {
            checkStatuslist += obj.id + ',';
        });
        checkStatuslist = checkStatuslist.substr(0, (checkStatuslist.length - 1));
        var ids = checkStatuslist; //得到 1，2，4
        var url = "{:url('admin/Welfare/auditall')}";
        var sUrl = "{:url('admin/Welfare/index')}";
        var eUrl = "{:url('admin/Welfare/index')}";
        //deleteAll(ids,请求的url,操作成功跳转url,操作失败跳转url)
        admin.operateAll(ids, url, sUrl, eUrl);
    });
    /**
     * 批量发放
     */
    $('#allsend').on('click', function() {
        var checkStatus = table.checkStatus('idTest'),
            checkStatusdata = checkStatus.data;
        var checkStatuslist = '';
        $.each(checkStatusdata, function(i, obj) {
            checkStatuslist += obj.id + ',';
        });
        checkStatuslist = checkStatuslist.substr(0, (checkStatuslist.length - 1));
        var ids = checkStatuslist; //得到 1，2，4
        var url = "{:url('admin/Welfare/sendall')}";
        var sUrl = "{:url('admin/Welfare/index')}";
        var eUrl = "{:url('admin/Welfare/index')}";
        //deleteAll(ids,请求的url,操作成功跳转url,操作失败跳转url)
        admin.operateAll(ids, url, sUrl, eUrl);
    });
});

</script>
</body>
</html>